<include file='Common:header' />

<!-- /section:basics/navbar.layout -->
<div class="main-container" id="main-container">

	<!-- #section:basics/sidebar -->

	<include file='Common:left' />
	<!-- /section:basics/sidebar -->

	<div class="main-content">
		<div class="main-content-inner">
			<div class="page-content">
				<div class="row maintop">

					<div class="col-xs-12 col-sm-3">
						<button class="btn btn-xs btn-danger" data-toggle="modal" data-target="#myModal">
							<i class="ace-icon fa fa-plus bigger-110"></i>
							添加自定义菜单
						</button>
						<!--<a class="red" href="javascript:;" onclick="we_menu_make();">-->
						<a class="red" href="javascript:;" onclick="return we_menu_make();">
							<button class="btn btn-xs btn-info" id="we_menu_make">
								<i class="ace-icon fa fa-bolt bigger-110"></i>
								生成菜单
							</button>
						</a>
					</div>
				</div>

				<div class="row">
					<div class="col-xs-12">
						<div>
							<form id="we_menu_order" name="we_menu_order" method="post" action="{:U('we_menu_order')}" >
								<table class="table table-striped table-bordered table-hover" id="dynamic-table">
									<thead>
									<tr>
										<th>ID</th>
										<th>主菜单名称</th>
										<th class="hidden-sm hidden-xs">菜单类型</th>
										<th>菜单状态</th>
										<th class="hidden-sm hidden-xs">菜单操作值</th>
										<th>排序</th>
										<th style="border-right:#CCC solid 1px;">操作</th>
									</tr>
									</thead>

									<tbody>

									<foreach name="we_menu" item="v">
										<tr>
											<td height="28">{$v.we_menu_id}</td>
											<td style='padding-left:<if condition="$v.leftpin neq 0">{$v.leftpin}px</if>' >{$v.lefthtml}{$v.we_menu_name}</td>
											<td class="hidden-sm hidden-xs">{$v.we_menu_type}</td>
											<td>
												<if condition='$v.we_menu_open eq 1'>
													<a class="red" href="javascript:;" onclick="return stateyes({$v.we_menu_id});" title="已显示">
														<div id="zt{$v.we_menu_id}"><button class="btn btn-minier btn-yellow">显示</button></div>
													</a>
													<else/>
													<a class="red" href="javascript:;" onclick="return stateyes({$v.we_menu_id});" title="已隐藏">
														<div id="zt{$v.we_menu_id}"><button class="btn btn-minier btn-danger">隐藏</button></div>
													</a>
												</if>
											</td>
											<td class="hidden-sm hidden-xs">{$v.we_menu_typeval}</td>
											<td><input name="{$v.we_menu_id}" class="list_order" value=" {$v.we_menu_order}" size="3"/></td>
											<td>
												<div class="hidden-sm hidden-xs action-buttons">
													<a class="green"  href="javascript:;" onclick="return we_menu_edit({$v.we_menu_id});"  title="修改">
														<i class="ace-icon fa fa-pencil bigger-130"></i>
													</a>
													<a class="red del" href="{:U('we_menu_del',array('we_menu_id'=>$v['we_menu_id']))}" title="删除">
														<i class="ace-icon fa fa-trash-o bigger-130"></i>
													</a>
												</div>
												<div class="hidden-md hidden-lg">
													<div class="inline position-relative">
														<button class="btn btn-minier btn-primary dropdown-toggle" data-toggle="dropdown" data-position="auto">
															<i class="ace-icon fa fa-cog icon-only bigger-110"></i>
														</button>
														<ul class="dropdown-menu dropdown-only-icon dropdown-yellow dropdown-menu-right dropdown-caret dropdown-close">
															<li>
																<a href="javascript:;" onclick="return we_menu_edit({$v.we_menu_id});" class="tooltip-success" data-rel="tooltip" title="" data-original-title="修改">
																	<span class="green">
																		<i class="ace-icon fa fa-pencil bigger-120"></i>
																	</span>
																</a>
															</li>

															<li>
																<a href="{:U('we_menu_del',array('we_menu_id'=>$v['we_menu_id']))}" class="tooltip-error del" data-rel="tooltip" title="" data-original-title="删除">
																	<span class="red">
																		<i class="ace-icon fa fa-trash-o bigger-120"></i>
																	</span>
																</a>
															</li>
														</ul>
													</div>
												</div>
											</td>
										</tr>
									</foreach>
									<tr>
										<td colspan="8" align="left"><button type="submit"  id="btnorder" class="btn btn-white btn-yellow btn-sm">排序</button></td>
									</tr>
									</tbody>
								</table>
							</form>
						</div>
					</div>
				</div>
				<include file='Common:header_nav' />


				<!-- 显示添加模态框（Modal）-->
				<div class="modal fade" id="myModal" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
					<form class="form-horizontal" name="we_menu_runadd" id="we_menu_runadd" method="post" action="{:U('we_menu_runadd')}">
						<div class="modal-dialog">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" class="close" data-dismiss="modal"
											aria-hidden="true">×
									</button>
									<h4 class="modal-title" id="myModalLabel">
										添加自定义菜单
									</h4>
								</div>
								<div class="modal-body">

									<div class="row">
										<div class="col-xs-12">

											<div class="form-group">
												<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 上级栏目： </label>
												<div class="col-sm-10">
													<select name="we_menu_leftid"  class="col-sm-4 selector" >
														<option value="0">顶级栏目</option>
														<foreach name="menu_top" item="v">
															<option value="{$v.we_menu_id}">{$v.we_menu_name}</option>
														</foreach>
													</select>
												</div>
											</div>
											<div class="space-4"></div>

											<div class="form-group">
												<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 菜单名称：  </label>
												<div class="col-sm-10">
													<input type="text" name="we_menu_name" id="we_menu_name" placeholder="输入菜单名称" class="col-xs-10 col-sm-5" />
												</div>
											</div>
											<div class="space-4"></div>

											<div class="form-group">
												<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 菜单类型： </label>
												<div class="col-sm-10">
													<select name="we_menu_type"  class="col-sm-4" >
														<option value="1" selected>URL菜单链接</option>
														<option value="2">关键词回复菜单</option>
													</select>
												</div>
											</div>
											<div class="space-4"></div>

											<div class="form-group">
												<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> URL地址：  </label>
												<div class="col-sm-10">
													<input type="text" name="we_menu_typeval" id="we_menu_typeval" placeholder="输入URL地址" class="col-xs-10 col-sm-10" />
												</div>
											</div>
											<div class="space-4"></div>

											<div class="form-group">
												<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 排序：  </label>
												<div class="col-sm-10">
													<input type="text" name="we_menu_order" id="we_menu_order" value="50" class="col-xs-10 col-sm-2" />
													<span class="lbl">&nbsp;&nbsp;<span class="red">*</span>从小到大排序</span>
												</div>
											</div>
											<div class="space-4"></div>

											<div class="form-group">
												<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 是否开启： </label>
												<div class="col-sm-10" style="padding-top:5px;">
													<input name="we_menu_open" id="we_menu_open" value="1" class="ace ace-switch ace-switch-4 btn-flat" type="checkbox" />
													<span class="lbl">&nbsp;&nbsp;默认关闭</span>
												</div>
											</div>
											<div class="space-4"></div>

										</div>
									</div>




								</div>
								<div class="modal-footer">
									<button type="submit" class="btn btn-primary">
										提交保存
									</button>
									<button class="btn btn-info" type="reset">
										重置
									</button>
									<button type="button" class="btn btn-default" data-dismiss="modal">
										关闭
									</button>
								</div>
							</div><!-- /.modal-content -->
						</div><!-- /.modal-dialog -->
					</form>
				</div><!-- /.modal -->








				<!-- 修改自定义菜单模态框（Modal） -->
				<div class="modal fade in" id="myModaledit" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
					<div class="modal-backdrop fade in" id="gbbb" style="height: 100%;"></div>
					<form class="form-horizontal" name="we_menu_runedit" id="we_menu_runedit" method="post" action="{:U('we_menu_runedit')}">
						<input type="hidden" name="we_menu_id" id="editwe_menu_id" value="" />
						<div class="modal-dialog">
							<div class="modal-content">
								<div class="modal-header">
									<button type="button" class="close" id="gb"  data-dismiss="modal"
											aria-hidden="true">×
									</button>
									<h4 class="modal-title" id="myModalLabel">
										修改友情链接
									</h4>
								</div>
								<div class="modal-body">


									<div class="row">
										<div class="col-xs-12">

											<div class="form-group">
												<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 上级栏目： </label>
												<div class="col-sm-10">
													<select name="we_menu_leftid"  id="editwe_menu_leftid"  class="col-sm-4 selector" >
														<option value="0">顶级栏目</option>
														<foreach name="menu_top" item="v">
															<option value="{$v.we_menu_id}">{$v.we_menu_name}</option>
														</foreach>
													</select>
												</div>
											</div>
											<div class="space-4"></div>

											<div class="form-group">
												<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 菜单名称：  </label>
												<div class="col-sm-10">
													<input type="text" name="we_menu_name" id="editwe_menu_name" placeholder="输入菜单名称" class="col-xs-10 col-sm-5" />
												</div>
											</div>
											<div class="space-4"></div>

											<div class="form-group">
												<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> 菜单类型： </label>
												<div class="col-sm-10">
													<select name="we_menu_type"  class="col-sm-4" id="editwe_menu_type">
														<option value="1" selected>URL菜单链接</option>
														<option value="2">关键词回复菜单</option>
													</select>
												</div>
											</div>
											<div class="space-4"></div>

											<div class="form-group">
												<label class="col-sm-2 control-label no-padding-right" for="form-field-1"> URL地址：  </label>
												<div class="col-sm-10">
													<input type="text" name="we_menu_typeval" id="editwe_menu_typeval" placeholder="输入URL地址" class="col-xs-10 col-sm-10" />
												</div>
											</div>
											<div class="space-4"></div>

										</div>
									</div>





								</div>
								<div class="modal-footer">
									<button type="submit" class="btn btn-primary">
										提交保存
									</button>
									<button type="button" class="btn btn-default" id="gbb" >
										关闭
									</button>
								</div>
							</div><!-- /.modal-content -->
						</div><!-- /.modal-dialog -->
					</form>
				</div><!-- /.modal -->



				<script>
					$(function(){
						//删除操作
						var $del = $(".del");
						$del.click(function(){
							var $url=this.href;
							layer.confirm('你确定要删除吗？', {icon: 3}, function(index){
							layer.close(index);
							$.get($url, function(data){
								if(data.status){
									layer.alert(data.info, {icon: 6}, function(index){
										layer.close(index);
										window.location.href=data.url;
									});
								} else {
									layer.alert(data.info, {icon: 5}, function(index){
										layer.close(index);
										//window.location.href="{:U('we_menu_list')}";
									});
								}
							}, "json");
							});
							return false;
						});
						//添加操作
						$('#we_menu_runadd').ajaxForm({
							beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
							success: complete, // 这是提交后的方法
							dataType: 'json'
						});

						function checkForm(){
							if( '' == $.trim($('#we_menu_name').val())){
								layer.alert('菜单名称不能为空', {icon: 5}, function(index){
									layer.close(index);
									$('#we_menu_name').focus();
								});
								return false;
							}
						}
						function complete(data){
							if(data.status==1){
								layer.alert(data.info, {icon: 6}, function(index){
									layer.close(index);
									window.location.href=data.url;
								});
							}else{
								layer.alert(data.info, {icon: 5}, function(index){
									layer.close(index);
									window.location.href="{:U('we_menu_list')}";
								});
								return false;
							}
						}
					});

					//状态操作
					function stateyes(val){
						$.post('{:U("we_menu_state")}',
								{x:val},
								function(data){
									var $v=val;
									if(data.status){
										if(data.info=='状态禁止'){
											var a='<button class="btn btn-minier btn-danger">隐藏</button>'
											$('#zt'+val).html(a);
											layer.alert(data.info, {icon: 5});
										}else{
											var b='<button class="btn btn-minier btn-yellow">显示</button>'
											$('#zt'+val).html(b);
											layer.alert(data.info, {icon: 6});
										}

									}else{
										layer.alert(data.info, {icon: 5});
									}
								});
						return false;
					}

					//生成菜单
					function we_menu_make(){
						$.get('{:U("we_menu_make")}',
								function(data){
									if(data.status==1){
										layer.alert(data.info, {icon: 6});
									}else{
										layer.alert(data.info, {icon: 5});
									}
								});
						return false;
					}




					//排序提交
					$(function(){
						$('#we_menu_order').ajaxForm({
							success: complete, // 这是提交后的方法
							dataType: 'json'
						});

						function complete(data){
							if(data.status==1){
								layer.alert(data.info, {icon: 6}, function(index){
									layer.close(index);
									window.location.href=data.url;
								});
							}else{
								layer.alert(data.info, {icon: 5}, function(index){
									layer.close(index);
									//window.location.href="{:U('we_menu_list')}";
								});
							}
						}
					});

					//显示修改自定义菜单
					function we_menu_edit(val){
						$.post('{:U("we_menu_edit")}',
								{we_menu_id:val},
								function(data){
									if(data.status==1){
										$(document).ready(function(){
											$("#myModaledit").show(300);
											$("#editwe_menu_id").val(data.we_menu_id);
											$("#editwe_menu_name").val(data.we_menu_name);
											$("#editwe_menu_leftid").val(data.we_menu_leftid);
											$("#editwe_menu_type").val(data.we_menu_type);
											$("#editwe_menu_typeval").val(data.we_menu_typeval);
										});
									}else{
										layer.alert(data.info, {icon: 5});
									}
								});
						return false;
					}

					//修改模态框状态
					$(document).ready(function(){
						$("#myModaledit").hide();
						$("#gb").click(function(){
							$("#myModaledit").hide(200);
						});
						$("#gbb").click(function(){
							$("#myModaledit").hide(200);
						});
						$("#gbbb").click(function(){
							$("#myModaledit").hide(200);
						});
					});
					//修改操作
					$(function(){
						$('#we_menu_runedit').ajaxForm({
							beforeSubmit: checkForm, // 此方法主要是提交前执行的方法，根据需要设置
							success: complete, // 这是提交后的方法
							dataType: 'json'
						});

						function checkForm(){
							if( '' == $.trim($('#editwe_menu_name').val())){
								layer.alert('菜单名称不能为空', {icon: 5}, function(index){
									layer.close(index);
									$('#editwe_menu_name').focus();
								});
								return false;
							}
						}
						function complete(data){
							if(data.status==1){
								layer.alert(data.info, {icon: 6}, function(index){
									layer.close(index);
									window.location.href=data.url;
								});
							}else{
								layer.alert(data.info, {icon: 5}, function(index){
									layer.close(index);
									window.location.href="{:U('we_menu_list')}";
								});
								return false;
							}
						}
					});


				</script>
			</div><!-- /.page-content -->
		</div>
	</div><!-- /.main-content -->
	<include file='Common:footer' />

</div><!-- /.main-container -->
</body>
</html>
